package com.kinyx.framework.utils;

import java.util.function.Supplier;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.enums.impl.ErrorCodeX;
import com.kinyx.framework.exception.KRuntimeException;
import com.kinyx.framework.function.Handler;

public class KStringUtils_Tester_checkBlankAndCompare {

	@Test
	public void test() {
		final Supplier<String> bothBlank = () -> { return "X"; };
		final Handler notEquals = () -> {};

		Assert.assertEquals("X", KStringUtils.checkBlankAndCompare(null, null, bothBlank, notEquals));
		Assert.assertEquals("X", KStringUtils.checkBlankAndCompare("", "", bothBlank, notEquals));

		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", null, bothBlank, notEquals));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare(null, "foo", bothBlank, notEquals));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", "foo", bothBlank, notEquals));

		Assert.assertNull(KStringUtils.checkBlankAndCompare("foo", "bar", bothBlank, notEquals));

		Assert.assertThrows(KRuntimeException.class, () -> {
			KStringUtils.checkBlankAndCompare("foo", "bar", bothBlank, () -> { throw new KRuntimeException(ErrorCodeX.NeverHappens); });
		});
	}

	@Test
	public void test2() {
		final Supplier<String> bothBlank = () -> { return "X"; };
		final Handler notEquals12 = () -> { System.out.println("12"); };
		final Handler notEquals13 = () -> { System.out.println("13"); };
		final Handler notEquals23 = () -> { System.out.println("23"); };

		Assert.assertEquals("X", KStringUtils.checkBlankAndCompare(null, null, null, bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("X", KStringUtils.checkBlankAndCompare("", "", "", bothBlank, notEquals12, notEquals13, notEquals23));

		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", null, null, bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare(null, "foo", null, bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare(null, null, "foo", bothBlank, notEquals12, notEquals13, notEquals23));

		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", "foo", null, bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare(null, "foo", "foo", bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", null, "foo", bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertEquals("foo", KStringUtils.checkBlankAndCompare("foo", "foo", "foo", bothBlank, notEquals12, notEquals13, notEquals23));

		Assert.assertNull("foo", KStringUtils.checkBlankAndCompare("foo", "bar", null, bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertNull("foo", KStringUtils.checkBlankAndCompare(null, "foo", "bar", bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertNull("foo", KStringUtils.checkBlankAndCompare("foo", null, "bar", bothBlank, notEquals12, notEquals13, notEquals23));
		Assert.assertNull("foo", KStringUtils.checkBlankAndCompare("foo", "bar", "qux", bothBlank, notEquals12, notEquals13, notEquals23));

	}

}
